package com.zlj;

import com.github.pagehelper.PageInfo;
import com.group.www.Application;
import com.group.www.pojo.*;
import com.group.www.service.impl.*;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.util.Date;
import java.util.List;

@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes= Application.class)
public class test {
    @Autowired
    private BrandfinancingServiceImp brandfinancingServiceImp;
    @Autowired
    private BrandRegisterServiceImp brandRegisterServiceImp;
    @Autowired
    private CategoryInfoServiceImp categoryInfoServiceImp;
    @Autowired
    private GoodsInfoServiceImp goodsInfoServiceImp;
    @Autowired
    private AddressInfoServiceImp addressInfoServiceImp;
    @Autowired
    private  CartInfoServiceImp cartInfoServiceImp;
    @Autowired
    private  CustomerfinancingServiceImp customerfinancingServiceImp;
    @Test
    public void BrandfinancingTest(){
        Brandfinancing brandfinancing=new Brandfinancing();
        brandfinancing.setBfId(1);
        BrandInfo brandInfo=new BrandInfo();
        brandInfo.setBrandid(2);
        brandfinancing.setBrand(brandInfo);
        brandfinancing.setIsexamine(50);
        brandfinancing.setIsRecharge(1000);
        brandfinancing.setMoney(100f);
        /*boolean flag=brandfinancingServiceImp.add(brandfinancing);
        PageInfo<Brandfinancing> page= brandfinancingServiceImp.queryAll(0,0,2);
        System.out.println(page.getList().size());*/
       /* Brandfinancing bf= brandfinancingServiceImp.queryById(2);
        System.out.println(bf);
        boolean flag= brandfinancingServiceImp.updateBrand(brandfinancing);
        System.out.println(flag);*/
       boolean flag= brandfinancingServiceImp.daleteBrand(brandfinancing);
        System.out.println(flag);
    }
    @Test
    public void BrandRegisterTest(){
        BrandRegister brandRegister=new BrandRegister();
        brandRegister.setBrid(1);
        brandRegister.setBrandlogo("aa");
        brandRegister.setBrandname("bb");
        brandRegister.setRemark("cc");
        boolean flag= brandRegisterServiceImp.add(brandRegister);
        System.out.println(flag);
        List<BrandRegister> list= brandRegisterServiceImp.queryAll();
        System.out.println(list.size());
        BrandRegister br=brandRegisterServiceImp.queryById(1);
        System.out.println(br);
        boolean falgs= brandRegisterServiceImp.daleteBrand(brandRegister);
        System.out.println(falgs);
    }
    @Test
    public void categoryInfoTest(){
        CategoryInfo categoryInfo=new CategoryInfo();
        categoryInfo.setCategoryid(1);
        categoryInfo.setCategoryname("裤子sss");
        /*查询
        List<CategoryInfo> list= categoryInfoServiceImp.query();
        for (CategoryInfo cf:list
             ) {
            System.out.println(cf);
        }*/
       /*添加
       boolean flag= categoryInfoServiceImp.add(categoryInfo);
       System.out.println(flag);*/
       /*根据id查询
       CategoryInfo cf= categoryInfoServiceImp.queryById(1);
       System.out.println(cf);*/
       /*删除*/
        boolean flag=categoryInfoServiceImp.deleteMany("2");
        System.out.println(flag);
       /*修改
       boolean flag= categoryInfoServiceImp.update(categoryInfo);
       System.out.println(flag);*/
       /*返回前10条数据
       List<CategoryInfo> list= categoryInfoServiceImp.queryAllCategoryInfo();
       System.out.println(list.size());*/
    }
    @Test
    public void GoodsInfoTest(){
        GoodsInfo entity=new GoodsInfo();
        BrandInfo brandInfo=new BrandInfo();
        CategoryInfo categoryInfo=new CategoryInfo();
        categoryInfo.setCategoryid(1);
        brandInfo.setBrandid(1);
        entity.setGoodsid(12);
        entity.setBrand(brandInfo);
        entity.setCategory(categoryInfo);
        entity.setGoodsimage("aa");
        entity.setGoodsname("ss");
        entity.setGoodsnum(50);
        entity.setGoodsprice(10f);
        entity.setGoodsremark("aabb");
        entity.setIshot(0);
        entity.setIsnew(0);
        entity.setIsrecommend(1);
        entity.setIssale(1);
        entity.setSaletime(new Date());
        entity.setSalesnum(20);/*
      GoodsInfo good = goodsInfoServiceImp.queryById(9);
       System.out.println(good);*/
     /* boolean flag=goodsInfoServiceImp.add(entity);
      System.out.println(flag);*/
     /*boolean flag=goodsInfoServiceImp.update(entity);
      System.out.println(flag);*/
       /* boolean flag=goodsInfoServiceImp.delete(entity);
        System.out.println(flag);*/
        List<GoodsInfo> list=  goodsInfoServiceImp.query();
        for (GoodsInfo gs:
                list) {
            System.out.println(gs);

        }
        /*boolean flag=goodsInfoServiceImp.updateSaleById(9,1);
        System.out.println(flag);*/
        /*List<GoodsInfo> list= goodsInfoServiceImp.queryAll(1,0,2,"","").getList();
        for (GoodsInfo gs:
             list) {
            System.out.println(gs);

        }*/

    }
    @Test
    public  void  AddressInfoTest(){
        AddressInfo entity=new AddressInfo();
        entity.setAddress("北京bb");
        entity.setIsdefault(0);
        UserInfo userInfo=new UserInfo();
        userInfo.setUserid(1);
        entity.setUser(userInfo);

        /*查询*/
        List<AddressInfo> list= addressInfoServiceImp.query();
        for (AddressInfo addressInfo: list) {
            System.out.println(addressInfo);
        }
       /*添加
        boolean flag=  addressInfoServiceImp.add(entity);
        System.out.println(flag);*/

        /*修改
        boolean flag=addressInfoServiceImp.update(entity);
        System.out.println(flag);*/

        /*删除
        boolean flag =addressInfoServiceImp.deleteAddressInfoByuserId(1,1);
        System.out.println(flag);*/
    }
    @Test
    public void  CartInfoTest(){
        CartInfo entity=new CartInfo();
        GoodsInfo goodsInfo=new GoodsInfo();
        goodsInfo.setGoodsid(10);
        UserInfo userInfo=new UserInfo();
        userInfo.setUserid(1);
        entity.setGoods(goodsInfo);
        entity.setAddcarttime(new Date());
        entity.setGoodsnums(100);
        entity.setUser(userInfo);/*
        boolean flag= cartInfoServiceImp.add(entity);
        System.out.println(flag);*/
       /* boolean flag=cartInfoServiceImp.update(entity.getUser().getUserid(),entity.getGoods().getGoodsid(),entity.getGoodsnums());
           System.out.println(flag);
        */
       /*List<CartInfo> list=cartInfoServiceImp.queryCartInfoByuserid(1);
        for (CartInfo cartInfo:
             list) {
            System.out.println(cartInfo);

        }*/
        boolean flag=cartInfoServiceImp.deleteCartInfoby(1,9);
        System.out.println(flag);
    }
    @Test
    public  void  CustomerfinancingTest(){
        Customerfinancing customerfinancing=new Customerfinancing();
        UserInfo userInfo=new UserInfo();
        userInfo.setUserid(1);
        customerfinancing.setCfId(1);
        customerfinancing.setIsexamine(0);
        customerfinancing.setIsRecharge(1);
        customerfinancing.setUser(userInfo);
        customerfinancing.setMoney(60f);
        List  list= customerfinancingServiceImp.query();
        System.out.println(list+""+list.size());
        /*boolean flag= customerfinancingServiceImp.add(customerfinancing);
        System.out.println(flag);*/
        /*boolean flag =customerfinancingServiceImp.update(customerfinancing);
        System.out.println(flag);*/
       /* customerfinancingServiceImp.delete(customerfinancing);*/
        PageInfo<Customerfinancing> page= customerfinancingServiceImp.queryAll(0,0,2);
        System.out.println(page.getList().size());
    }
}
